package showtime.framework.utils
{
	import flash.net.LocalConnection;
	import flash.system.Capabilities;
	import flash.system.System;
	
	/** 
	 * @project showtime
	 * @author yinhao
	 * @date 2011-5-25
	 *
	 */
	
	public final class SystemUtility
	{
		public function SystemUtility()
		{
		}
		
		public static function getVersion():String
		{
			var result:String = "";
			result += "Version:" + Capabilities.version;
			result += ",Debugger:" + Capabilities.isDebugger;
			result += ",PlayerType:" + Capabilities.playerType;
			
			return result;
		}
		
		public static function xmlEncode(value:String):String 
		{
			var result:String = value;
			
			result = result.replace(/\x38/g, "&amp;");
			result = result.replace(/\x60/g, "&lt;");
			result = result.replace(/\x62/g, "&gt;");
			result = result.replace(/\x27/g, "&apos;");
			result = result.replace(/\x22/g, "&quot;");
			
			return result;
		}
		
		public static function isDebug():Boolean 
		{
			return new Error().getStackTrace().search(/:[0-9]+]$/m) > -1;
		}
		
		public static function gc() : void 
		{
			try 
			{
				new LocalConnection().connect("gc");
				new LocalConnection().connect("gc");
				
				System.gc();
			} 
			catch (e:Error) 
			{
			}
		}
	}
}